using System;
using System.Runtime.Serialization;

namespace DataLayer.Types
{
    [Serializable]
    public class BudgetItem : BaseRecord<BudgetItem>, ISerializable
    {

        private string m_note;
        private decimal m_amount;
        private bool m_Active;
        private FrequencyItem m_frequency;
        private CategoryItem categoryItem;
        private BalanceType balanceType;

        public BudgetItem()
        {
        }

        #region Public Properties

        public virtual FrequencyItem Frequency
        {
            get
            {
                return m_frequency;
            }
            set
            {
                m_frequency = value;
                OnPropertyChanged("Frequency");
            }
        }

        public virtual CategoryItem Category
        {
            get
            {
                return categoryItem;
            }
            set
            {
                categoryItem = value;
                OnPropertyChanged("Category");
            }
        }

        public virtual BalanceType BalanceType
        {
            get
            {
                return balanceType;
            }
            set
            {
                balanceType = value;
                OnPropertyChanged("BalanceType");
            }
        }

        public virtual string Note
        {
            get
            {
                return m_note;
            }
            set
            {
                m_note = value;
                OnPropertyChanged("Note");
            }
        }

        public virtual decimal Amount
        {
            get
            {
                return m_amount;
            }
            set
            {
                m_amount = value;
                OnPropertyChanged("Amount");
            }
        }

        public virtual bool Active
        {
            get
            {
                return m_Active;
            }
            set
            {
                m_Active = value;
                OnPropertyChanged("Active");
            }
        }


        #endregion

        #region IBaseRecord Members


        public virtual void Save()
        {
            base.Save(this);
        }

        public virtual void Delete()
        {
            base.Delete(this);
        }


        #endregion

//        #region IEquatable<BudgetItem> Members
//
//        public virtual bool Equals(BudgetItem budgetItem)
//        {
//            return Id == budgetItem.Id;
//        }
//
//        #endregion


        public virtual void Merge(BudgetItem budgetItem)
        {
            m_name = budgetItem.Name;
            m_note = budgetItem.Note;
            m_amount = budgetItem.Amount;
            m_Active = budgetItem.Active;
        }

        #region ISerializable Members

        public BudgetItem(SerializationInfo info, StreamingContext context)
        {
            Id = info.GetInt32("Id");
            Name = info.GetString("Name");
            Note = info.GetString("Note");
            Amount = info.GetDecimal("Amount");
            Active = info.GetBoolean("Active");
        }

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("Id", Id);
            info.AddValue("Name", Name);
            info.AddValue("Note", Note);
            info.AddValue("Amount", Amount);
            info.AddValue("Active", Active);
        }

        #endregion
    }
}
